<template>
	<view class="content">
		<view class="topBox">
			<view class="title flex">
				<u-icon size="17" name="arrow-left" color="#fff" @click="goBack"></u-icon>
				<view class="pl244">店铺管理</view>
			</view>
			<view class="top">
				<view class="left flex">
					<image class="userAvatar" :src="userInfo.avatar?userInfo.avatar:'../../../static/images/userAvatar.png'" mode="">
					</image>
					<view class="">
						<view class="flex">
							<text class="text mr32">{{userInfo.nickname}}</text>
							<text class="vip"
								v-if="userInfo.platformLevelDo && userInfo.platformLevelDo.levelName">{{userInfo.platformLevelDo.levelName}}</text>
						</view>
						<view class="flex phoneBox">
							<image class="phoneIcon" src="@/static/images/phone.png" mode=""></image>
							<view class="text">{{userInfo.phone.substr(0,3) + "****" + userInfo.phone.substr(7)}}</view>
						</view>
					</view>
				</view>
				<view class="right" @click="goCodePage">
					<image class="qrcode" src="@/static/images/code.png" mode=""></image>
					<view class="text">推广名片</view>
				</view>
			</view>
		</view>

		<view class="data">
			<image class="bg" src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/gerenzhongxin/my_icon1.png"
				mode=""></image>
			<view class="hide"></view>
			<view class="title flex-between pore">
				<view class="flex"><view class="lineText"></view>商家数据</view>
				<view class="rightTitle" @click="changeData">{{todayShow?'本月':'今日'}}数据
					<image class="sort2"
						src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon7.png"
						mode=""></image>
				</view> 
			</view>
			<view class="item flex-between pore">
				<view class="itemL">
					{{todayShow?'今日':'本月'}}营业额(元)
					<view class="price">
						<text class="pIcon">￥</text>{{todayShow?turnover[3].value:turnover[6].value || 0}}
					</view>
				</view>
				<view class="itemL">
					{{todayShow?'今日':'本月'}}订单数
					<view class="price">
						<text class="pIcon">￥</text>{{todayShow?turnover[4].value:turnover[7].value || 0}}
					</view>
				</view>
			</view>
			<view class="userItem flex-between pore" style="margin-top: 24rpx;">
				<view class="left">
					<view class="titleL">
						<image class="img"
							src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon11.png"
							mode=""></image>可推商家数量
					</view>
					<view class="num">{{agentInformation.allowToOpen || 0}}</view>
				</view>
				<view class="left">
					<view class="titleL">
						<image class="img"
							src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon11.png"
							mode=""></image>已开设店铺数量
					</view>
					<view class="num">{{agentInformation.currentManagement || 0}}</view>
				</view>
			</view>
		</view>
		<!-- 我的推广 -->
		<view class="promote">
			<view class="title flex" style="margin-bottom: 0;">
				<view class="lineText"></view>商家列表
			</view>
			<ren-dropdown-filter :filterData='filterData' :defaultIndex='defaultIndex'
			@onSelected='onSelected'></ren-dropdown-filter>
			<view class="" v-if="agentStoreList.length>0">
				<view class="item" v-for="(store, index) in agentStoreList" :key="index">
					<text class="time">开店时间:{{store.createTime}}</text>
					<view class="contain">
						<view class="left flex">
							<image class="userAvatar2" :src="store.image?store.image:'../../../static/images/userAvatar.png'" mode="">
							</image>
							<view class="">
								<view class="flex">
									<text class=" bName">{{ store.storeName }}</text>
									<text class="vip" style="padding: 2rpx 8rpx;" :class="store.storeClassType==0?'type1':store.storeClassType==1?'type2':'type3'">{{storeType[store.storeClassType]}}</text>
								</view>
								<view class="flex phoneBox" v-if="store.storeAddress">
									<image class="phoneIcon"
										src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/Desktop/dianpu_icon4.png"
										mode=""></image>
									<view class="bPhone ellipsis" :style="{width:store.expireType==0?'400rpx':'300rpx'}">{{ store.storeAddress }}河南省河南省河南省河南省河南省河南省河南省河南省河南省河南省河南省</view>
								</view>
							</view>
						</view>
						<view class="right" v-if="store.expireType==1">
							<image src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/Desktop/dianpu_icon5.png"
								mode=""></image>
							即将到期
						</view>
						<view class="right2" v-if="store.expireType==2">
							<image src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/Desktop/dianpu_icon5.png"
								mode=""></image>
							已到期
						</view>
					</view>
					<view class="bottom flex-between">
						<view class="bItem">
							<view class="num">
								<text class="pIcon">￥</text>{{ store.todaySales || 0 }}
							</view>
							今日营业额(元）
						</view>
						<view class="bItem">
							<view class="num">
								{{ store.todayOrderCount || 0 }}
							</view>
							今日订单数
						</view>
						<view class="bItem">
							<view class="num">
								<text class="pIcon">￥</text>{{ store.todayIncome || 0 }}
							</view>
							今日佣金(元)
						</view>
					</view>
				</view>
			</view>
			<view class="" v-else>
				<emptyPage title='暂无店铺~'></emptyPage>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from "vuex";
	import {
		getUserInfo
	} from '@/api/user.js';
	import {
		getAgentInformation,
		getTurnover,
		getAgentStoreList
	} from '@/api/business.js';
	import emptyPage from '@/components/emptyPage.vue';
	import RenDropdownFilter from '@/components/ren-dropdown-filter/ren-dropdown-filter.vue'
	export default {
		components: {
			emptyPage,
			RenDropdownFilter
		},
		data() {
			return {
				userInfo: {phone:'***********'},
				agentInformation: {},
				turnover: [{value:0},{value:0},{value:0},{value:0},{value:0},{value:0},{value:0},{value:0}],
				agentStoreList: [],
				todayShow:true,//今日数据  本月数据
				storeType:{
					'0':'基础版',
					'1':'标准版',
					'2':'旗舰版',
				},
				filterData:[
				    [{ text: '默认排序', value: '' }, { text: '基础版', value: 0 }, { text: '标准版', value: 1 }, { text: '旗舰版', value: 2 }]
				],
				defaultIndex:[0],
				storeClassType:''
			}
		},
		onLoad() {
			this.getUserDetail();
		},
		methods: {
			goGoodsList() {
				uni.switchTab({
					url: "/pages/goods_cate/goods_cate"
				})
			},
			viewTeam() {
				uni.navigateTo({
					url: "/pages/users/team/team"
				})
			},
			// 返回上一个页面
			goBack() {
				uni.navigateBack()
			},
			// 今日/本月数据切换
			changeData() {
				this.todayShow = !this.todayShow
			},
			// 跳转到推广名片页面
			goCodePage() {
				uni.navigateTo({
					url: '/pages/users/promoteCard/index'
				});
			},
			getUserDetail() {
				getUserInfo().then((res) => {
					this.userInfo = res.data;
					this.getStoreDetail(this.userInfo.uid);
				});
			},
			getStoreDetail(id) {
				getAgentInformation(id).then(res => {
					this.agentInformation = res.data;
				});
				getTurnover(id).then(res => {
					this.turnover = res.data;
				});
				this.getList()
			},
			getList(){
				getAgentStoreList({
					uid:this.userInfo.uid,
					storeClassType:this.storeClassType
				}).then(res => {
					this.agentStoreList = res.data;
				});
			},
			onSelected(res){
				this.agentStoreList = []
				this.storeClassType = res[0][0].value
				this.getList();
			},
		}
	}
</script>

<style lang="scss">
	.content {
		padding-bottom: 60rpx;
	}

	.topBox {
		background: #2393FF;
		padding: 108rpx 32rpx 150rpx;
		border-radius: 0 0 30rpx 30rpx;

		.title {
			font-size: 32rpx;
			color: #FFFFFF;
			margin: 0rpx 0 48rpx;
			text-align: center;
		}
	}

	.userAvatar {
		width: 76rpx;
		height: 76rpx;
		border-radius: 50%;
		margin-right: 12rpx;
	}

	.userAvatar2 {
		width: 70rpx;
		height: 70rpx;
		border-radius: 4rpx;
		margin-right: 12rpx;
	}

	.top {
		padding: 38rpx 24rpx 24rpx;
		background: linear-gradient(180deg, #CCE3FD 0%, #F4F9FF 51%, #FFFFFF 100%);
		box-shadow: 0px 6px 12px 2px rgba(204, 204, 204, 0.16);
		border-radius: 12rpx;
		border: 2rpx solid #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.left {
			.text {
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: 700;
				font-size: 32rpx;
				color: #28314C;
			}

			.phoneIcon {
				width: 23rpx;
				height: 28rpx;
				margin-right: 6rpx;
			}

			.phoneBox {
				margin-top: 14rpx;

				.text {
					font-family: D-DIN, D-DIN;
					font-weight: 700;
					font-size: 24rpx;
					color: #637697;
				}
			}

			.vip {
				border-radius: 4rpx 4rpx 20rpx 4rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: #28314C;
				padding: 2rpx 20rpx;
				background: linear-gradient(91deg, #F2F2F4 0%, #CBCED4 100%);
			}

			.mr32 {
				margin-right: 32rpx;
			}
		}

		.right {
			display: flex;
			flex-direction: column;
			align-items: center;

			.qrcode {
				width: 48rpx;
				height: 48rpx;
				margin-bottom: 8rpx;
			}

			.text {
				font-family: PingFang SC Medium, PingFang SC Medium;
				font-size: 24rpx;
				color: #515B71;
				font-weight: 400;
			}
		}
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.flex-all-center {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.flex-between {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
	}

	.data {
		position: relative;
		width: 686rpx;
		margin: -120rpx 0 24rpx 32rpx;
		padding: 24rpx;
		z-index: 3;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 686rpx;
			height: 366rpx;
			z-index: 1;
		}

		.hide {
			padding: 17rpx 24rpx 0 0;
			position: absolute;
			right: 0rpx;
			top: 10rpx;
			width: 324rpx;
			height: 64px;
			background: #D7EEFF;
			border-radius: 12rpx;
			font-size: 24rpx;
			color: #637697;
			z-index: 0;
			text-align: right;
		}

		.title {
			font-weight: 700;
			font-size: 32rpx;
			color: #28314C;
			margin-bottom: 26rpx;
			font-family: "Alibaba PuHuiTi 2.0-85 Bold";
			
			.rightTitle{
				font-weight: 400;
				font-size: 24rpx;
				color: #637697;
			}
		}

		.lineText {
			width: 8rpx;
			height: 34rpx;
			background: #2393FF;
			border-radius: 4px 4px 4px 4px;
			margin-right: 12rpx;
		}

		.item {

			.itemL {
				width: 50%;
				font-size: 24rpx;
				color: #28314C;
			}

			.price {
				display: flex;
				align-items: flex-end;
				font-family: 'DIN';
				font-weight: 700;
				font-size: 56rpx;
				color: #2393FF;
				margin-top: 4rpx;

				.pIcon {
					font-size: 24rpx;
					margin: 0 6rpx 10rpx 0;
				}
			}
		}

		.userItem {
			margin-top: 32rpx;

			.left {
				width: 307rpx;
				height: 122rpx;
				background: #F8FBFF;
				border-radius: 12rpx;
				padding: 14rpx 28rpx 0;

				.titleL {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: #28314C;

					image {
						width: 30rpx;
						height: 24rpx;
						margin-right: 6rpx;
					}

					.img {
						width: 30rpx;
						height: 27rpx;
						margin-right: 4rpx;
					}
				}

				.num {
					font-family: 'DIN';
					font-weight: 700;
					font-size: 56rpx;
					color: #28314C;
					margin-left: 32rpx;
				}
			}
		}
	}

	.pore {
		position: relative;
		z-index: 1;
	}

	.promote {
		margin: 0 32rpx;
		padding: 32rpx 32rpx;
		background: #FFFFFF;
		box-shadow: 0px 6px 12px 0px rgba(204, 204, 204, 0.1569);
		border-radius: 12rpx;

		.title {
			font-weight: 700;
			font-size: 32rpx;
			color: #28314C;
			margin-bottom: 24rpx;
			font-family: "Alibaba PuHuiTi 2.0-85 Bold"
		}

		.lineText {
			width: 8rpx;
			height: 34rpx;
			background: #2393FF;
			border-radius: 4px 4px 4px 4px;
			margin-right: 12rpx;
		}

		.sort {
			font-size: 24rpx;
			color: #637697;
			padding: 0rpx 0 8rpx 0;
			border-bottom: 2rpx solid #E5E5E5;

			image {
				width: 23rpx;
				height: 21rpx;
				margin-left: 10rpx;
			}
		}

		.item {
			position: relative;
			margin-top: 24rpx;
			padding: 64rpx 24rpx 26rpx;
			background: linear-gradient(180deg, #CCE3FD 0%, #F4F9FF 16%, #FFFFFF 100%);
			box-shadow: 0px 6px 12px 0px rgba(204, 204, 204, 0.1569);
			border-radius: 12rpx;

			.time {
				position: absolute;
				top: 0;
				left: 0;
				background: #0077FF;
				border-radius: 12rpx 0px 16rpx 0px;
				font-size: 20rpx;
				color: #FFFFFF;
				padding: 8rpx 40rpx 8rpx 24rpx;
			}

			.bottom {
				padding-top: 20rpx;

				.bItem {
					font-size: 24rpx;
					color: #637697;

					.num {
						font-family: 'DIN';
						font-weight: 700;
						font-size: 40rpx;
						color: #2393FF;

						.pIcon {
							font-size: 24rpx;
						}
					}

				}

				.btn {
					width: 178rpx;
					height: 62rpx;
					line-height: 62rpx;
					background: #0077FF;
					border-radius: 42rpx;
					text-align: center;
					font-size: 24rpx;
					color: #FFFFFF;
				}
			}
		}
	}

	.contain {
		padding: 0rpx 0rpx 24rpx;
		border-radius: 12rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 2rpx solid #E5E5E5;

		.left {
			.text {
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: 700;
				font-size: 32rpx;
				color: #28314C;
			}

			.phoneIcon {
				width: 18rpx;
				height: 22rpx;
				margin-right: 6rpx;
			}

			.phoneBox {
				margin-top: 14rpx;

				.text {
					font-family: D-DIN, D-DIN;
					font-weight: 700;
					font-size: 24rpx;
					color: #637697;
				}
			}

			.vip {
				border-radius: 4rpx 4rpx 20rpx 4rpx;
				font-weight: bold;
				font-size: 20rpx;
				color: #FFFFFF;
				padding: 6rpx 20rpx;
				// background: linear-gradient(91deg, #FF700A 0%, #FE980B 100%);
			}

			.mr32 {
				margin-right: 32rpx;
			}
		}

		.right {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 178rpx;
			height: 50rpx;
			background: #0077FF;
			border-radius: 42rpx;
			font-weight: 500;
			font-size: 24rpx;
			color: #FFFFFF;

			image {
				width: 28rpx;
				height: 28rpx;
				margin-right: 14rpx;
			}
		}
		.right2 {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 154rpx;
			height: 50rpx;
			background: #FF3C0A;
			border-radius: 42rpx;
			font-weight: 500;
			font-size: 24rpx;
			color: #FFFFFF;
		
			image {
				width: 28rpx;
				height: 28rpx;
				margin-right: 14rpx;
			}
		}
	}

	.bName {
		color: #28314C;
		margin-right: 32rpx;
		font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
		font-weight: 700;
		font-size: 28rpx;
	}

	.bPhone {
		font-family: 'DIN';
		font-weight: 700;
		font-size: 24rpx;
		color: #637697;
		width: 400rpx;
	}

	.bTotal {
		font-size: 24rpx;
		color: #637697;

		text {
			font-family: DIN;
			font-weight: 700;
			font-size: 32rpx;
			color: #637697;
		}
	}

	.pl244 {
		padding-left: 244rpx;
	}

	.sort2 {
		width: 23rpx;
		height: 21rpx;
		margin-left: 10rpx;
	}
	.type1{
		background: linear-gradient( 91deg, #FF700A 0%, #FE980B 100%);
	}
	.type2{
		background: linear-gradient( 91deg, #CE6AFF 0%, #D997FF 100%);
	}
	.type3{
		background: linear-gradient( 91deg, #FF7D53 0%, #FF8578 100%);
	}
</style>